package com.zhbg.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zhbg.mapper.RightsMapper;
import com.zhbg.pojo.Rights;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class RightsServiceImpl implements RightsService{
    @Autowired
    private RightsMapper rightsMapper;
    @Override
    public List<Rights> getRightsList() {
        QueryWrapper<Rights> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("parent_id",0);
       List<Rights> oneList = rightsMapper.selectList(queryWrapper);
       for(Rights oneRights: oneList){//遍历结合
           queryWrapper.clear();
           queryWrapper.eq("parent_id", oneRights.getId());
           List<Rights> twoList = rightsMapper.selectList(queryWrapper);
           oneRights.setChildren(twoList);
       }
        return oneList;
    }

    @Override
    public List<Rights> getRightsListAll() {
        List<Rights> rightsList = rightsMapper.selectList(null);
        return rightsList;
    }

}
